package cz.muni.fi.pa165.sportclubmanager.entity;

/**
 *
 * @author xondrusk
 */
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(uniqueConstraints = {
    @UniqueConstraint(columnNames = {"team_id", "player_id"}),
    @UniqueConstraint(columnNames = {"team_id", "number"})
})
public class PlayerOnRoster implements Serializable {

    // id generated automaticaly
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    // relation many to one, joined on column team_id
    @ManyToOne
    @JoinColumn(name = "team_id")
    private Team team;
    // relation many to one, joined on column player_id
    @ManyToOne
    @JoinColumn(name = "player_id")
    private Player player;
    // number of player with given id in given team
    private int number;

    // <editor-fold defaultstate="collapsed" desc="Constructors">
    public PlayerOnRoster() {
    }

    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Equals and HashCode">
    @Override
    public boolean equals(Object obj) {
        if (obj == null || id == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PlayerOnRoster other = (PlayerOnRoster) obj;
        if (this.id != other.id && (!this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 67 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Getters and Setters">
    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Team getTeam() {
        return this.team;
    }

    public void setTeam(Team team) {
        this.team = team;
    }

    public Player getPlayer() {
        return this.player;
    }

    public void setPlayer(Player player) {
        this.player = player;
    }

    public int getNumber() {
        return this.number;
    }

    public void setNumber(int number) {
        this.number = number;
    }
    // </editor-fold>

    @Override
    public String toString() {
        return "PlayerOnRoster{" + "id=" + id + ", team={" + team.getId() + ","+team.getName()+"}, player=" + player.getId() + ", number=" + number + '}';
    }
    
    
}